﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DBA.Data;
using DBA.Data.ADO;

namespace DBA.Web.SystemManage.BaseCodeManage
{
    public partial class DeptManage : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack) return;
            Bind(1, null);
        }

        DataAccessLibrary dal = CommonQuery.DataAccessLibrary;

        protected void linkBtnSearch_Click(object sender, EventArgs e)
        {
            IDictionary<String, String> dict = new Dictionary<String, String>();
            dict.Add("Name", txtMemberId.Text.Trim());
            ViewState["conditions"] = dict;
            Bind(1, dict);
        }

        protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
        {
            IDictionary<String, String> dict = null;
            if (ViewState["conditions"] != null)
            {
                dict = (IDictionary<String, String>)ViewState["conditions"];
            }
            Bind(e.NewPageIndex, dict);
        }

        private void Bind(int pageIdx, IDictionary<String, String> dict)
        {

            string sql = "select * from sys_department where 1 = 1 ";
            if (dict != null)
            {
                if (dict["Name"] != null)
                {
                    sql += "and Name like '%'+@Name+'%'";
                    dal.ManagerParameter.AddNewInParameter("Name", dict["Name"].ToString());
                }
            }


            int iCount = 0;

            replData.DataSource = dal.ModifyData.GetPageDataTable("(" + sql + ")", "*", "", "dpt_id DESC", pageIdx, 10, ManagerSQL.PageViewTableType.MixtureTable, ref iCount);
            replData.DataBind();
            AspNetPager1.RecordCount = iCount;

        }

        protected void linkBtnMaskSearch_Click(object sender, EventArgs e)
        {
            //IDictionary<String, String> dict = new Dictionary<String, String>();
            //dict.Add("UserName", txtMaskMemberId.Text.Trim());
            //ViewState["conditions"] = dict;
            //Bind(1, dict);
        }

        protected void linkBtnDeleSelect_Click(object sender, EventArgs e)
        {
            if (!String.IsNullOrEmpty(hidDeleString.Value))
            {
                string value = hidDeleString.Value;
                string sql = "delete from [sys_department] where dpt_id in (" + value + ");";
                dal.ExecuteNonQuery(sql);
                if (String.IsNullOrEmpty(dal.ErrorMessage))
                {
                    Bind(1, null);
                    ScriptManager.RegisterStartupScript(this, base.GetType(), "deleOk" + System.Guid.NewGuid().ToString(), "parent.alertMsg.correct('数据删除成功');", true);
                }
                else
                {
                    ScriptManager.RegisterStartupScript(this, base.GetType(), "deleOk" + System.Guid.NewGuid().ToString(), "parent.alertMsg.error('数据删除失败');", true);
                }
            }
        }
    }
}